# install default datasource to grafana

apiVersion: 1

# remove provisioned data sources
deleteDatasources: []

# install following data sources
datasources:

{% for ip in hostvars  if hostvars[ip].pg_role == 'primary' %}

###### {{ hostvars[ip].pg_cluster }} ##############################
{% if hostvars[ip].pg_databases|length > 0 %}
{% for db in hostvars[ip].pg_databases  %}
  - name: {{ hostvars[ip].pg_cluster }}.{{ db.name }}
    type: postgres
    url: {{ inventory_hostname }}:{{ pg_port }}
    access: proxy
    user: {{ pg_monitor_username }}
    database: {{ db.name }}
    editable: true
    jsonData: {
      "connMaxLifetime": 14400,
      "maxIdleConns": 8,
      "maxOpenConns": 8,
      "postgresVersion": 1300,
      "sslmode": "disable",
      "tlsAuth": false,
      "tlsAuthWithCACert": false
    }
    secureJsonData:
      password: {{ pg_monitor_password }}

{% endfor %}
{% endif %}


{% endfor %}